package main

import (
	"fmt"
	"sync"
)

type T struct{}

var (
	x  int64
	wg sync.WaitGroup
)

func add(done chan<- T) {
	mutex := make(chan T, 1)
	for i := 0; i < 5000; i++ {
		mutex <- T{}
		x++
		<-mutex
	}
	done <- T{}
}

func main() {
	done := make(chan T)
	done1 := make(chan T)
	go add(done)
	go add(done1)

	<-done
	<-done1
	fmt.Println(x)
}
